//
//  CZEmotionCollectionView.swift
//  weibo
//
//  Created by 丁蒙 on 16/7/4.
//  Copyright © 2016年 丁蒙. All rights reserved.
//

import UIKit
//cell重用标识
private let CZEmotionCollectionViewcellId = "CZEmotionCollectionViewcellId"

class CZEmotionCollectionView: UICollectionView {

    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 设置视图
    private func setupUI() {
        //注册
        registerClass(CZEmoticonCell.self, forCellWithReuseIdentifier: CZEmotionCollectionViewcellId)
        
        dataSource = self
        
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        
        layout.scrollDirection = .Horizontal
        
    }

}

// MARK: - UICollectionViewDataSource

extension CZEmotionCollectionView: UICollectionViewDataSource {
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return CZEmoticonTools.sharedEmoticonTools.allEmoticons.count
        
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return CZEmoticonTools.sharedEmoticonTools.allEmoticons[section].count
        
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(CZEmotionCollectionViewcellId, forIndexPath: indexPath) as! CZEmoticonCell
        cell.emoticons = CZEmoticonTools.sharedEmoticonTools.allEmoticons[indexPath.section][indexPath.item]
        return cell
        
    
        }
}